<template>
  <div class="form-area">
    <div class="row">
      <div class="col">广告名称</div>
      <div class="form-control">
        <input type="text" class="input-text" v-model="advName">
      </div>
    </div>
    <div class="row">
      <div class="col">广告位置</div>
      <div class="form-control">
        <select class="select" v-model="advPosition">
          <option value="首页轮播1">首页轮播1</option>
          <option value="首页轮播2">首页轮播2</option>
          <option value="首页轮播3">首页轮播3</option>
        </select>
      </div>
    </div>
    <div class="row">
      <div class="col">广告类型</div>
      <div class="form-control">
        <select class="select" v-model="advType">
          <option value="食品广告">食品广告</option>
          <option value="汽车广告">汽车广告</option>
          <option value="家居广告">家居广告</option>
        </select>
      </div>
    </div>
    <div class="row">
      <div class="form-btn">
        <button class="btn btn-middle" @click="save">保存</button>
        <button class="btn btn-middle" @click="goBack">返回</button>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  name: 'editAdvManage',
  data () {
    return {
      advName: '',
      advPosition: '',
      advType: ''
    }
  },
  methods: {
    save () {
      let $this = this
      axios.post('/api/saveAdv', {
        id: $this.$route.params.id,
        advName: $this.advName,
        advPosition: $this.advPosition,
        advType: $this.advType
      }).then(function (res) {
        if (res.status === 200) {
          if (res.data.success === true) {
            $this.$router.push('/adManage')
          }
        }
      }).catch(function (err) {
        console.log(err)
      })
    },
    goBack () {
      this.$router.go(-1)
    }
  },
  mounted () {
    let $this = this
    let data = ''
    axios.post('/api/getEditAdv', {
      id: $this.$route.params.id
    }).then(function (res) {
      if (res.status === 200) {
        if (res.data !== null) {
          data = res.data
          $this.advName = data.advName
          $this.advPosition = data.advPosition
          $this.advType = data.advType
        }
      }
    }).catch(function (err) {
      console.log(err)
    })
  }
}
</script>

<style scoped>
.form-area {
  background-color: #fff;
  padding: 20px;
  font-size: 14px;
}
</style>
